package month4.day19;

import java.util.*;

public class C5 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        Map<Object, Object> map = new HashMap<>();
        map.put("猫", "cat");
        map.put("老虎", "tiger");
        map.put("猪", "pig");
        map.put("狗", "dog");
        map.put("鸭子", "duck");
        //个数
        System.out.println(map.size());
        //输出键集
        System.out.println(map.keySet());
        //输出所有值
        System.out.println(map.values());
        while (true) {
            System.out.println("请输入您需要的翻译功能序号，1：汉译英，2：英译汉");
            int a = in.nextInt();
            if (a == 1) {
                System.out.println("请输入需要进行翻译的中文");
                String Chinese = in.next();
                if (map.containsKey(Chinese)) {
                    System.out.println(map.get(Chinese));
                    break;
                } else
                    System.out.println("暂时无法翻译");
            } else if (a == 2) {
                System.out.println("请输入需要进行翻译的英文：");
                String English = in.next();
                //Map.entrySet 方法返回映射的 collection 视图
                Set<Map.Entry<Object, Object>> set = map.entrySet();
                Iterator<Map.Entry<Object, Object>> ir = set.iterator();
                while (ir.hasNext()) {
                    Map.Entry entry = ir.next();
                    //getValue()返回与此项对应的值
                    if (entry.getValue().equals(English)) {
                        System.out.println(entry.getKey());
                        break;
                    }
                }
                System.out.println("暂时无法翻译");
            }
        }
    }
}
